import axios from 'axios';
import {
	Message
} from 'element-ui' //全局引入
import store from '../store.js'
axios.defaults.baseURL = 'http://120.53.31.103:84/api/';

axios.interceptors.request.use(config => {
	config.headers['Authorization'] = 'Bearer' + store.state.token;
	return config;
})

axios.interceptors.response.use(config => {
	if (config.status !== 200 && config.data.data.code !== 200) {
		Message.error(config.data.data.msg)
	} else {
		return Promise.resolve(config)
	}

	error => {
		Message.error("操作失败！")
		return Promise.reject(error);
	}
});

export default {
	// 登录
	getLogin({
		mobile,
		password
	}) {
		return axios.post('adminUser/login', {
			mobile,
			password
		})
	},
	// 获取菜单
	getMenu() {
		return axios.post('menu/info')
	},
	// 获取学生列表
	getStudent({
		page,
		limit,
		status,
		nickname,
		mobile,
	}) {
		return axios.get('user', {
			page,
			limit,
			status,
			nickname,
			mobile,
		})
	},
	// 添加学员
	getAddUser({
		avatar,
		birthday,
		province_id,
		city_id,
		district_id,
		mobile,
		nickname,
	}) {
		return axios.post('user', {
			avatar,
			birthday,
			province_id,
			city_id,
			district_id,
			mobile,
			nickname,
		})
	},
	//获取省
	 getProvince(){
		 return axios.get('sonArea/0');
	 },
	 // 获取市
	 getCity(id){
		 return axios.get('sonArea/'+id);
	 },
	 // 获取区
	 getDistrict(id){
		 return axios.get('sonArea/'+id)
	 },
	 // 获取详情页
	 getDeatils(){
		 return axios.get('user/')
	 }
		 
}
